<?php

/* @var $article \frontend\modules\yii\models\FrameArticles */
/* @var $sidebar \frontend\modules\yii\models\FrameDir */

use yii\bootstrap\Html;
use yii\bootstrap\Modal;
use yii\bootstrap\ActiveForm;
use frontend\modules\yii\models\FrameArticles;
use yii\helpers\ArrayHelper;
use frontend\modules\yii\models\FrameCatalogue;
use yii\web\AssetManager;
use yii\web\View;

frontend\modules\yii\assets\ztree\ZtreeAsset::register($this);
//$markdown = frontend\modules\yii\assets\markdown\MarkdownAsset::register($this);



echo "<div class='container-fluid row article-body' >";

echo Html::beginTag("div", ["class" => "col-xs-2 article-sidebar"]);

//$form = ActiveForm::begin(["id" => "catalogue-form", "layout" => "horizontal"]);
$catalogue = FrameCatalogue::find()->asArray()->all();
$catalogue = array_combine(ArrayHelper::getColumn($catalogue, "id"), ArrayHelper::getColumn($catalogue, "cname"));
echo Html::dropDownList("catalogue", null, $catalogue, ["class" => "form-control"]);
echo Html::button("添加页面", ["class" => "btn btn-sm btn-success", "style" => "margin:10px 10px 10px 0px;", "data-toggle" => "modal", "data-target" => "#addNodeDialog"]);
echo Html::button("添加目录", ["class" => "btn btn-sm btn-success", "style" => "margin:10px;"]);
//data-toggle="modal" data-target="#myModal"
echo \frontend\modules\yii\widgets\Ztree::widget([
    "nodes" => \frontend\modules\yii\models\FrameDir::getNodes()
]);


echo Html::endTag("div");

echo Html::beginTag("div", ["class" => "col-xs-10 article-markdown"]);
echo \frontend\modules\yii\widgets\Markdown::widget([
    "upload" => "upload-image",
    //"baseUrl" => $markdown->baseUrl,
]);

echo Html::button("Save", ["class" => "btn btn-primary", "onclick" => "saveArticle()"]);
echo Html::endTag("div");


echo "</div>";











Modal::begin([
    'id' => "addNodeDialog",
    'header' => '<h2>Add Node</h2>',
]);

$form = ActiveForm::begin(["id" => 'dir-form']);
echo $form->field($sidebar, "dname")->label("Name")->textInput(['autofocus' => true]);
echo Html::submitButton('Save', ['class' => 'btn btn-primary', 'name' => 'login-button']);
ActiveForm::end();

Modal::end();


$css = <<<CSS
.content-body {
    margin: 0!important;
}
.article-body {
    /*position:fixed;*/
    left: 0;
    top: 0;
    margin-top: 50px;
}
.article-sidebar {
    margin-top:10px;
}
.article-markdown {
    height: calc(100vh);
}
CSS;

$this->registerCss($css);

$js = <<<JS
function saveArticle(){
    $.ajax({
        type: "POST",
        url: "save-article",
        data: {
            
        }
    })
}
JS;
